package com.xy.mainp.base;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.xy.AnimUtils;
import com.xy.mainp.R;
import com.xy.mainp.main.widget.TittleBar;
import com.xy.mainp.utils.StatusBarUtil;

/**
 * @author ocy
 * @time 2016/10/31 22:58
 * @des ${TODU}
 */

public abstract class TittleBarActivity extends BasePActivity {

    protected TittleBar tittleBar;
    private View rootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        initTitleBar();
        super.onCreate(savedInstanceState);

    }

    private void initTitleBar() {
        tittleBar = TittleBar.initTittleBar(new FrameLayout(this));
        StatusBarUtil.setImmersiveStatusBar(this, getResources().getColor(R.color.title_bar));
        super.setContentView(tittleBar.getContainer());
    }

    @Override
    public void setContentView(int layoutResID) {
        this.rootView = LayoutInflater.from(this).inflate(layoutResID, null, false);
        setContentView(rootView);
    }

    @Override
    public void setContentView(View view) {
        this.rootView = view;
        if (tittleBar != null) {
            tittleBar.setContentView(view);
        } else {
            super.setContentView(view);
        }
    }

    public void setTitlebar(TittleBar titlebar) {
        if (titlebar != null) {
            titlebar.attachedTo(this);
            this.tittleBar = titlebar;
        }
    }

    protected void initTitleName() {
        String title = getTitle().toString();
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }
    }

    @Override
    public void setTitle(CharSequence title) {
        super.setTitle(title);
        if (tittleBar != null) {
            tittleBar.setTittle(title);
        }
    }

    public void setTitle(View view) {
        if (tittleBar != null) {
            tittleBar.setTittle(view);
        }
    }


    public void hideTittltBar(boolean refHeight) {
        tittleBar.isHideTittleBar(true,refHeight);
    }

    public void showTittltBar(boolean refHeight) {
        tittleBar.isHideTittleBar(false,refHeight);
    }
}
